package com.wc.alorithm_blue_bridge._DFS.Q3935;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.ArrayList;

/**
 * @Author congege
 * @Description 仙境诅咒
 * https://www.lanqiao.cn/problems/3935/learning/?page=1&first_category_id=1
 * @Date Created in 2023/11/27-18:47
 */
public class Main {
    public static void main(String[] args) {
        ArrayList<int[]> xys = new ArrayList<>();
        Input sc = new Input();
        int n = sc.nextInt();
        // map[i][j]   1 ： 仙人位置  2：表示仙人被染了
        int[][] map = new int[2 * 1000 + 1][2 * 1000 + 1];
        int x, y;
        for (int i = 0; i < n; i++) {
            x = sc.nextInt();
            y = sc.nextInt();
            x += 1000;
            y += 1000;
            // 1 表示是仙人位置
            map[x][y] = 1;
            xys.add(new int[]{x, y});
        }
        int d = sc.nextInt();
        x = xys.get(0)[0];
        y = xys.get(0)[1];
        map[x][y] = 2;
        dfs(map, x, y, d);
        for (int i = 0; i < n; i++) {
            x = xys.get(i)[0];
            y = xys.get(i)[1];
            System.out.println(map[x][y] / 2);
        }
    }

    /**
     * 移动感染
     * @param map
     * @param x
     * @param y
     * @param d
     */
    public static void dfs(int[][] map, int x, int y, int d) {
        int up = Math.max(0, x - d);
        int down = Math.min(map.length - 1, x + d);
        while (up <= down) {
            int bound = (int) Math.sqrt(d * d - (x - up) * (x - up));
            int left = Math.max(0, y - bound);
            int right = Math.min(map.length - 1, y + bound);
            while (left <= right) {
                if (map[up][left] == 1) {
                    map[up][left] = 2;
                    dfs(map, up, left, d);
                }
                map[up][left] = 2;
                left++;
            }
            up++;
        }
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }
}
